package com.nan.buy.service.Impl;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.nan.buy.dao.OrdersMapper;
import com.nan.buy.model.OrderDetails;
import com.nan.buy.model.Orders;
import com.nan.buy.service.OrderDetailsService;
import com.nan.buy.service.OrdersService;

@Service
public class OrdersServiceImpl  implements OrdersService{

	@Resource
	private OrdersMapper ordersMapper;

	@Resource
	private OrderDetailsService orderDetailsService;

	@Override
	public List<Orders> selectOrders() {
		return ordersMapper.selectOrders();
	}

	@Override
	public int delOrders(String oId) {
		//刪除訂單的詳細信息
		int msg=orderDetailsService.deleteByOrdersId(oId);
		if(msg !=0){
			msg=ordersMapper.deleteByPrimaryKey(oId);
		}
		return msg;
	}

	@Override
	public Orders selectByPrimaryKey(String orderId) {
		return ordersMapper.selectByPrimaryKey(orderId);
	}

	@Override
	public int insertOrders(List<OrderDetails> OrderDetailsList,Orders record) {
		int msg=orderDetailsService.insertList(OrderDetailsList, record.getOrderId());
		if(msg != 0){
		msg=ordersMapper.insertSelective(record);
		}
		return msg;
	}
}
